package com.example.project7;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class SharedViewModel extends ViewModel {
    // 使用 MutableLiveData 来存储可变数据
    private final MutableLiveData<String> userEmail = new MutableLiveData<>();
    private final MutableLiveData<String> currentInterest = new MutableLiveData<>("未选择");
    private final MutableLiveData<Boolean> logoutEvent = new MutableLiveData<>();

    // 为外部提供不可变的 LiveData，防止数据被意外修改
    public LiveData<String> getUserEmail() {
        return userEmail;
    }

    public LiveData<String> getCurrentInterest() {
        return currentInterest;
    }

    public LiveData<Boolean> getLogoutEvent() {
        return logoutEvent;
    }

    // 更新数据的方法
    public void setUserEmail(String email) {
        userEmail.setValue(email);
    }

    public void setCurrentInterest(String interest) {
        currentInterest.setValue(interest);
    }

    public void logout() {
        logoutEvent.setValue(true);
    }

    public void onLogoutEventHandled() {
        logoutEvent.setValue(false);
    }
}